var signature = undefined;
//	alert($('.money').val());
var isBound = undefined;

function getQueryString(thisUrl,name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    //var r = window.location.search.substr(1).match(reg);
    var r1 = thisUrl.toString().split("?")[1];
    if(r1 != null){
        var r = r1.match(reg);
        if (r != null) return unescape(r[2]);
    }
    return null;

}



$.loginApp = function(lHttp,$routeParams,lPop,$scope){
    var url = encodeURIComponent(window.location.href);
    console.log(url);
    //alert(url)
    var loginToken = getQueryString(window.location,"loginToken");
    var mobile = getQueryString(window.location,"mobile");
    lat = getQueryString(window.location,"lat");
    lng = getQueryString(window.location,"lng");
    if(lat == null){
        lat = 0;
        lng = 0;
    }
    //alert(qrCode);
    //alert(url)
    //alert($routeParams)
    if($routeParams != undefined){
        linkStatic = $routeParams.state;
        //alert(linkStatic)
    }
    access_token = getCookie("pengtao_access_token");


    if(access_token == "" || access_token == undefined){
        lPop.popSet(2, $scope ,"正在认证中" ,undefined , "images/loding-icon.png" ,undefined ,undefined, "请耐心等待",  undefined ,undefined);
        gHttp({method:'JSONP', url: "http://mobile-api.imlaidian.com:8089/cdt/authWebAppLoginToken?loginToken="+loginToken+"&mobile="+mobile+"&callback=JSON_CALLBACK", timeout:5000})
            .then(function(response) {


            var json = response.data;
            var status = response.status;

            if(json.result == 1) {
                $scope.showPopTips = false;
                access_token = json.access_token;
                //第一次登陆查询一次用户信息
                setCookie("pengtao_access_token", access_token);
                $.updateUserInfo();
            }
            else{
                lPop.popSet(1, $scope ,json.msg ,"请重新登录" , "images/wrong-icon.png" ,undefined ,undefined, "确定",  null ,undefined);
            }
        }, function(response) {
            lPop.popSet(1, $scope ,"认证失败" ,"请重新登录" , "images/wrong-icon.png" ,undefined ,undefined, "确定",  null ,undefined);

        });

    }
    else{
        $.updateUserInfo();
    }


}